
layui.use(['form','laydate','table'], function () {
    let form = layui.form,
        layer = layui.layer,
        $ = layui.$;

   // laydate.render({elem: '#end_time'});
    //监听提交
    form.on('submit(saveBtn)', function (data) {

        //发异步，把数据提交给php
        $.ajax({
            url: '/admin/express/Save?action=ajax',
            type: 'post',
            dataType: 'json',
            data:data.field,
            success: function(res) {


                if (res.status == true) {
                    layer.msg('保存成功', {icon: 1, time: 1000},
                        function(){
                            parent.location.reload();
                        })

                }  else {
                    layer.open({
                        title: '错误信息',
                        content: '<span style="color:red">'+res.code+':</span>'+res.msg
                    })
                    return false
                }
            },
            error: function(re) {

                layer.open({
                    title: '错误信息',
                    content: '<span style="color:red">'+re.responseJSON.errorCode+':</span>'+re.responseJSON.msg
                })
            }
        });




    });

    //监听指定开关
    form.on('switch(switchTest)', function(data){

        if(data.value==1)
        {
            //关闭操作
            $("#bizpro_type").attr('style','display:none')
            $(this).val(2)

        }else{
            $("#bizpro_type").attr('style','')
            $(this).val(1)
        }


        //$(".additem").attr('style','')



    });
    //监听广告类型
    form.on('select(show_type)', function(data){
        let jump_address=$("#jump_address").parents('.layui-form-item')
        let pop_imgurl=$("input[name='pop_imgurl']").parents('.layui-form-item')
        let layui_form_text=$(".layui-form-text")

        //详情
        if(data.value==3)
        {
            jump_address.attr('style','display:none');
            pop_imgurl.attr('style','display:none');
            layui_form_text.attr('style','');
        }
        //跳转
        if(data.value==2)
        {
            jump_address.attr('style','');
            pop_imgurl.attr('style','display:none');
            layui_form_text.attr('style','display:none');
        }
        //弹窗
        if(data.value==1)
        {
            jump_address.attr('style','display:none');
            pop_imgurl.attr('style','');
            layui_form_text.attr('style','display:none');
        }
        //$(".additem").attr('style','')
    });
    //监听添加关联商品
    $(document).on('click','.additem',function(){
        additem_index=additem()
    });
    function additem() {
        let index=0
       let re= $.ajax({
            url: '/admin/adverbanner/bizpro' ,
            type: 'post',
            dataType: 'json',
           async : false,
            success: function(data) {
                 index=layer.open({
                    type: 1,
                    title: '选择商品',
                    resize: false,
                    move: false,
                    skin: 'layui-layer-rim',
                    area: ['500px', '500px'],
                    content: data.info
                });


            },
            error: function(re) {
                 index=layer.msg("连接失败,报错了");
            }
        });
        return index


    }

});










